﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2012
// admin@franknagl.de
//
namespace SBIP.Filter
{
    using System;

    /// <summary>
    /// Lighting filter for every rgb channel.
    /// </summary>
    /// 
    /// <remarks>
    /// <para>
    /// The filter adds specified values for every channel. 
    /// Every channel will increase by its specified value.
    /// 
    /// with intensity equal or lower than its threshold value is converted to black 
    /// channel (value 0). All other channels are converted to white channels (value 255), 
    /// when binarization is set. Otherwise the channels don't change.
    /// </para>
    /// 
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = new Bitmap( "cathedral.jpg" );
    ///
    /// // 1. Offline rendering of images
    /// // create Processor, used as rendering framework
    /// Processor processor = new Processor( );
    /// // starts Processor
    /// processor.Begin( image );
    /// // create Lighting filter
    /// Lighting filter = new Lighting( );
    /// processor.Filter = filter;
    /// // optional: configure filter
    /// filter.LightR = 150;
    /// filter.LightG = 150;
    /// filter.LightB = 150;
    /// // apply the filter, render to bitmap  
    /// Bitmap resultImage = processor.RenderToBitmap( );
    /// resultImage.Save( "Lighting.jpg", ImageFormat.Jpeg );
    /// // apply the filter, render to texture
    /// // Texture2D resultTexture = processor.RenderToTexture( );
    /// processor.End( );
    ///  
    /// // 2. Online rendering of videos or images
    /// // create any windows control for rendering in
    /// Form myForm = new Form
    /// {
    ///     Width = 1280,
    ///     Height = 720
    /// };
    /// // starts Processor
    /// processor.Begin( "Video.avi", myForm );
    /// // create Lighting filter
    /// filter = new Lighting( );
    /// processor.Filter = filter;
    /// // optional: configure filter
    /// filter.R = 100;
    /// filter.G = 100;
    /// filter.B = 100;
    /// // apply the filter
    /// myForm.Show( );
    /// while ( myForm.Created )
    /// {
    ///     processor.Render( );
    ///     Application.DoEvents( );
    /// }
    /// processor.End( );
    /// </code>
    /// 
    /// <para><b>Initial image:</b></para>
    /// <img src="../../Cathedral.jpg" width="500" height="338" />
    /// <para><b>Result image:</b></para>
    /// <img src="../../Lighting.jpg" width="500" height="338" />
    /// </remarks>
    public sealed class Lighting : BaseFilter
    {
        private int r;
        private int g;
        private int b;


        /// <summary>Light value for channel red.</summary>
        /// <remarks><para>Default value is set to 100.</para></remarks>
        public int LightR
        {
            get { return r; }
            set
            {
                if (Effect == null)
                    throw new ArgumentException("Light value for channel red" + InitMsg);

                r = value;
                Effect.Parameters["LightR"].SetValue(r);
            }
        }

        /// <summary>Light value for channel green.</summary>
        /// <remarks><para>Default value is set to 100.</para></remarks>
        public int LightG
        {
            get { return g; }
            set
            {
                if (Effect == null)
                    throw new ArgumentException("Light value for channel green" + InitMsg);

                g = value;
                Effect.Parameters["LightG"].SetValue(g);
            }
        }

        /// <summary>Light value for channel blue.</summary>
        /// <remarks><para>Default value is set to 100.</para></remarks>
        public int LightB
        {
            get { return b; }
            set
            {
                if (Effect == null)
                    throw new ArgumentException("Light value for channel blue" + InitMsg);

                b = value;
                Effect.Parameters["LightB"].SetValue(b);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Threshold"/> class.
        /// </summary>
        public Lighting()
            : base("Lighting") { }

        /// <summary>
        /// Initializes Light values.
        /// </summary>
        protected override void PostInit()
        {
            LightR = 100;
            LightG = 100;
            LightB = 100;
        }
    }
}
